package net.sangpil.classes.utils.userInterface
/**
* background image 부분 아직 안만들었음. 
*/
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;

	public class Btn extends Sprite
	{
		private var _bg:DisplayObject;
		private var _text:String;
		private var _tf:TextField;
		private var _tfCover:Sprite;
		private var _tff:TextFormat;
		
		public function Btn(text:String = 'not set', background:DisplayObject = null)
		{
			super();
			this._text = text;
			if(background != null)
			{
				this._bg = background;
			}
			this.makeClip();
			this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void
		{
			this.buttonMode = true;
		}
		
		private function makeClip():void
		{
			this.makeTf();	
			this.makeTfCover();
			this.resetSize();
		}
		
		private function makeTf():void
		{
			_tf = new TextField();
			_tff = new TextFormat();
			
			_tf.type = TextFieldType.DYNAMIC;
			_tf.text = _text;
			
			this.addChild(_tf);
			
		}
		
		private function makeTfCover():void
		{
			_tfCover = new Sprite();
			_tfCover.graphics.beginFill(0x333333, 0);
			_tfCover.graphics.drawRect(0,0,_tf.width, _tf.height);
			_tfCover.graphics.endFill();
			
			this.addChild(_tfCover);
		}
		
		public function get text():String
		{
			return _text;
		}
		
		public function set text(txt:String):void
		{
			_text = txt;
			this.resetSize();
		}
		
		private function resetSize():void
		{
			_tf.width = _tf.textWidth+5;
			_tf.height = _tf.textHeight+3;
			
			_tfCover.width = _tf.width;
			_tfCover.height = _tf.height;
		}
		
		public function set textColor(col:uint):void
		{
			_tff.color = col;
			this._tf.defaultTextFormat = _tff;
			_tf.text = _text;
		}
		
		public function set textSize(size:uint):void
		{
			_tff.size = size;
			this._tf.defaultTextFormat = _tff;
			_tf.text = _text;
			this.resetSize();
		}
		
		public function set textFont(font:String):void
		{
			_tff.font = font;
			this._tf.defaultTextFormat = _tff;
			_tf.text = _text;
			this.resetSize();
		}
		
		
		
	}
}